package com.inspur.edp.bff.core.buffer;

import com.inspur.edp.cef.api.dataType.base.IAccessorCreator;
import com.inspur.edp.cef.api.session.ICefSession;
import com.inspur.edp.cef.core.buffer.base.BufferManager;
import com.inspur.edp.cef.entity.accessor.base.IAccessor;
import com.inspur.edp.cef.entity.changeset.IChangeDetail;
import com.inspur.edp.cef.entity.entity.IEntityData;

public class BffBufferManager extends BufferManager {

    public BffBufferManager(ICefSession session, String entityType, IAccessorCreator accessorCreator) {
        super(session, entityType, accessorCreator);
    }

    public void clear() {
        this.getBuffers(this.getEntityType()).clear();
    }

    public IAccessor initCurrentBufferData(IEntityData data, boolean isReadOnly) {
        return initBufferByLevel(data, 1, isReadOnly);
    }

    public IAccessor initOriginalBufferData(IEntityData data, boolean isReadOnly) {
        return initBufferByLevel(data, 0, isReadOnly);
    }

    public IEntityData getCurrentData(String id) {
        return (IEntityData) getBuffer(id, 1);
    }

    public IEntityData getOriginalData(String id) {
        return (IEntityData) getBuffer(id, 0);
    }

    public IAccessor acceptCurrentChange(String dataId, IChangeDetail change) {
        return acceptChange(dataId, 1, change);
    }
}
